package org.socialresume.client.mvp.presenter;


import org.enunes.gwt.mvp.client.EventBus;
import org.enunes.gwt.mvp.client.presenter.BasePresenter;
import org.socialresume.client.mvp.event.AdminModeEvent;
import org.socialresume.client.mvp.event.handler.AdminModeEventHandler;
import org.socialresume.client.mvp.presenter.MainPresenter.Display;

import com.google.inject.Inject;

public class MainPresenterImpl extends BasePresenter<Display> implements MainPresenter {
	private HeaderPresenter headerPresenter;
	
	@Inject
	public MainPresenterImpl(EventBus eventBus, Display display,
            HeaderPresenter headerPresenter,
            BodyPresenter bodyPresenter,
            FooterPresenter footerPresenter) {
		super(eventBus, display);
		this.headerPresenter = headerPresenter;
		this.headerPresenter.bind();
		
        display.addHeader(this.headerPresenter.getDisplay());
        display.addBody(bodyPresenter.getDisplay());
        display.addFooter(footerPresenter.getDisplay());
	}
	
	@Override
	public void bind() {
		super.bind();
		registerHandler(eventBus.addHandler(AdminModeEvent.getType(), new AdminModeEventHandler() {
			
			@Override
			public void onAdminModeEvent(AdminModeEvent event) {
				setAdminMode(event.isAdminMode());
			}
		}));
	}
	
	public void setAdminMode(boolean adminMode){
		headerPresenter.setAdminMode(adminMode);
	}
}
